package org.algorithm.biubiu.wheel_1.树;

import org.algorithm.common.TreeNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * @author jzx
 * @date 2022/5/30
 * @desc {https://leetcode.cn/problems/binary-tree-inorder-traversal/}
 */
public class $5月31二叉树的中序遍历 {


    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList();
        if(root==null) return res;
        Stack<TreeNode> stack = new Stack();
        TreeNode dummy = root;

        while(!stack.isEmpty()|| dummy!=null){
            if(dummy!=null){
                stack.push(dummy);
                dummy = dummy.left;
            }else{
                dummy = stack.pop();
                res.add(dummy.val);
                dummy = dummy.right;
            }
        }
        return res;
    }
}
